Career advisor

In this part, we're going to create a cool tool based on LLMs that helps with your career questions. All you need to do is put in the job you're interested in, what the job is about, and your resume. Our smart tool will look at all that and give you some solid advice on how to move forward in your career. It's like having a chat with a career coach who knows all about jobs and how your skills fit in.

Alt text

Similarly, we will need to redesign the Gradio interface and make corresponding adjustments to the prompt. The finalized code follows:

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. 66
  67. 67
  68. 68
  69. 69
  70. 70
  71. 71
  72. 72
  1. # Import necessary packages
  2. from ibm_watsonx_ai import Credentials
  3. from ibm_watsonx_ai import APIClient
  4. from ibm_watsonx_ai.foundation_models import Model, ModelInference
  5. from ibm_watsonx_ai.foundation_models.schema import TextChatParameters
  6. from ibm_watsonx_ai.metanames import GenTextParamsMetaNames
  7. import gradio as gr
  8. # Model and project settings
  9. model_id = "meta-llama/llama-3-2-11b-vision-instruct" # Directly specifying the LLAMA3 model
  10. # Set credentials to use the model
  11. credentials = Credentials(
  12. url = "https://us-south.ml.cloud.ibm.com",
  13. )
  14. # Generation parameters
  15. params = TextChatParameters(
  16. temperature=0.7,
  17. max_tokens=1024
  18. )
  19. project_id = "skills-network"
  20. # Initialize the model
  21. model = ModelInference(
  22. model_id=model_id,
  23. credentials=credentials,
  24. project_id=project_id,
  25. params=params
  26. )
  27. # Function to generate career advice
  28. def generate_career_advice(position_applied, job_description, resume_content):
  29. # The prompt for the model
  30. prompt = f"Considering the job description: {job_description}, and the resume provided: {resume_content}, identify areas for enhancement in the resume. Offer specific suggestions on how to improve these aspects to better match the job requirements and increase the likelihood of being selected for the position of {position_applied}."
  31. messages = [
  32. {
  33. "role": "user",
  34. "content": [
  35. {
  36. "type": "text",
  37. "text": prompt
  38. },
  39. ]
  40. }
  41. ]
  42. # Generate a response using the model with parameters
  43. generated_response = model.chat(messages=messages)
  44. # Extract and format the generated text
  45. advice = generated_response['choices'][0]['message']['content']
  46. return advice
  47. # Create Gradio interface for the career advice application
  48. career_advice_app = gr.Interface(
  49. fn=generate_career_advice,
  50. flagging_mode="never", # Deactivate the flag function in gradio as it is not needed.
  51. inputs=[
  52. gr.Textbox(label="Position Applied For", placeholder="Enter the position you are applying for..."),
  53. gr.Textbox(label="Job Description Information", placeholder="Paste the job description here...", lines=10),
  54. gr.Textbox(label="Your Resume Content", placeholder="Paste your resume content here...", lines=10),
  55. ],
  56. outputs=gr.Textbox(label="Advice"),
  57. title="Career Advisor",
  58. description="Enter the position you're applying for, paste the job description, and your resume content to get advice on what to improve for getting this job."
  59. )
  60. # Launch the application
  61. career_advice_app.launch()

To run it:

  1. Create a new file and name it career_advisor.py.
  2. Enter the code provided above into this file.
  3. In the terminal, run
  1. 1
  1. python3.11 career_advisor.py
  1. Launch the application by clicking the following button.

If the application launches successfully, it should appear similar to:

Alt text

Now play with it! 🎉

(To terminate the script, press Ctrl+C in the terminal and close the appliction window.)

Exercise

Change the parameter temperature, which controls randomness of response. The higher the temperature, the more randomness. Compare the responses between different parameter settings.

Click here for the answer
  1. 1
  1. "temperature": 0.5

Great job! 🎉 Now you have learned how to create LLM-based applications using watsonx.ai!

In the next section, we'll guide you how to use watsonx.ai locally, allowing you to run it in your own environment.